<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改考勤详情')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-content-edit" th:object="${recordAttendContent}">
            <input name="contentId" id="contentId" th:field="*{contentId}" type="hidden">
            <input type="hidden" name="attendId" th:field="*{attendId}" id="attendId">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">员工姓名：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="userId" type="hidden" th:field="*{userId}"  />
                        <input class="form-control" type="text" onclick="selectUserTree()" id="treeName" readonly="true" th:field="*{userName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> <font color="red">考勤标记：出勤划“√”，正常休息划“/”，工休假划“*”，病假划“！”，事假划“@”，工伤划“#”，婚丧假划“$”，探亲假划“%”，调休划“^”，旷工划“X”，加班划“+”，产假划“&”。如某段时间为外派或借调他科室，期间考勤空缺由相应科室进行考勤，其他情况划“-”，并用文字说明。</font></span>
                </div>
            </div>
            <div class="form-group" th:each="date, dateStat : ${dateList}">
                <label class="col-sm-3 control-label">[[${date}]]：</label>
                <div class="col-sm-8">
                    <select th:name="'day'+${dateStat.count}" class="form-control m-b" th:with="type=${@dict.getType('attend_status')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{day__${dateStat.count}__}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "record/attend/content";
        $("#form-content-edit").validate({
            focusCleanup: true
        });

        /* 选择人员 */
        function selectUserTree() {
            var options = {
                title: '选择员工',
                width: "380",
                url: ctx + "basic/user/selectTree",
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            var treeType = body.find('#treeType').val();
            if(treeType == 'user'){
                var id = body.find('#treeId').val();
                var treeId = id.substring(id.indexOf('_') + 1, id.length);
                $("#treeId").val(treeId);
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
                checkRecordAttendContent();
            }else{
                $.modal.alertError("请选择员工");
            }
        }

        function checkRecordAttendContent(){
            $.ajax({
                type: "post",
                url: prefix + "/checkRecordAttendContent",
                dataType: 'json',
                data: {
                    userId: $("#treeId").val(),
                    attendId: $("#attendId").val(),
                    contentId: $("#contentId").val()
                },
                success: function(r) {
                    if (r.code != web_status.SUCCESS) {
                        $.modal.msgError('当前人员已存在考勤记录');
                    }
                    $.modal.closeLoading();
                }
            });
        }

        function submitHandler() {
            var treeId = $("#treeId").val();
            if(treeId == '') {
                $.modal.msgError('请先选择员工');
                return;
            }
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-content-edit').serialize());
            }
        }
    </script>
</body>
</html>